package com.careerraiser.xtra.thread;


	public class Deadlocker {
		 
	    String str1 = "Java";
	    String str2 = "UNIX";
	    public Deadlocker(){
	    	Thread.currentThread().setPriority(8);
	    }
	    Thread trd1 = new Thread("My Thread 1"){
	        public void run(){
	            while(true){
	            	System.out.println("Priority: "+Thread.currentThread().getPriority());
                	System.out.println("inside thread1");
	                synchronized(str1){
	                	System.out.println("str1 with thread1");
	                    synchronized(str2){
		                	System.out.println("str2 with thread1");
	                        System.out.println(str1 + str2);
	                    }
	                }
	            }
	        }
	    };
	     
	    Thread trd2 = new Thread("My Thread 2"){
	        public void run(){
	            while(true){
                	System.out.println("inside thread - 2");
                	System.out.println("Name: "+Thread.currentThread().getName());
                	System.out.println("Priority: "+Thread.currentThread().getPriority());

                	synchronized(str2){
	                	System.out.println("str2 with thread-2");
	                    synchronized(str1){
	                    	System.out.println("str1 with thread-2");
	                        System.out.println(str2 + str1);
	                    }
	                }
	            }
	        }
	    };
	     
	    public static void main(String a[]){
	        Deadlocker mdl = new Deadlocker();
	      //  Thread.currentThread().setPriority(8);
        	System.out.println("Priority: "+Thread.currentThread().getPriority());

	        mdl.trd2.start();
	        mdl.trd1.start();
	        //mdl.trd2.start();
	    }
	}


